<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话">
      </el-table-column>
    </el-table>
    <el-pagination
      align="right"
      background
      layout="prev, pager, next"
      :page-size = "pageSize"
      :total ="total"
      @current-change="currentChange"
    >
    </el-pagination>
  </div>
</template>
<script>
export default {
  methods:{
    currentChange(currentPage){
      this.currentPage = currentPage;
      this.pageList();
    },
    pageList(){
      this.pageSize =  parseInt(Math.random()*9+1);
      console.log(this.pageSize)
      this.$Http.post("/user/list",{"currentPage":this.currentPage,"pageSize":this.pageSize}).then(result=>{
        console.log(result.data);
        let rows = result.data.rows;
        let beginPage = (this.currentPage-1)*this.pageSize;
        let endPage =beginPage+this.pageSize;
        let list = rows.slice(beginPage,endPage);
        this.tableData = list;
        this.total = rows.length
      }).catch(()=>{
          console.log("err");
        }
      )
    },
  },
  data() {
    return {
      tableData: [],
      pageSize:10,
      total:5,
      currentPage:1
    }
  },mounted() {
    this.pageList();
  }
}
</script>
